package com.simple.util.common;


import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.salt.ZeroSaltGenerator;
import org.jasypt.util.password.ConfigurablePasswordEncryptor;

public class AESUtil {
    private final static String ALGORITHM = "PBEWITHSHA256AND128BITAES-CBC-BC";
    private final static String ALGORITHMSHA="SHA-512";
    private final static  StandardPBEStringEncryptor ENCRYPTOR = new StandardPBEStringEncryptor();
    private final static  ConfigurablePasswordEncryptor PASSWORD_ENCRYPTOR = new ConfigurablePasswordEncryptor();
    static {
        ENCRYPTOR.setProvider(new BouncyCastleProvider());
        ENCRYPTOR.setAlgorithm(ALGORITHM);
        ENCRYPTOR.setPassword(AESPropertyLoad.getInstance().getString("aeskey"));
        ENCRYPTOR.setSaltGenerator(new ZeroSaltGenerator()); 
        PASSWORD_ENCRYPTOR.setAlgorithm(ALGORITHMSHA);
        PASSWORD_ENCRYPTOR.setPlainDigest(false);
    }
    public static String encrypt(final String userId) {

        return ENCRYPTOR.encrypt(userId);
    }

    public static String decrypt(final String userId) {
        return ENCRYPTOR.decrypt(userId);
    }

    
    public static String passwordEncryptor(final String userPassword) {
        return PASSWORD_ENCRYPTOR.encryptPassword(userPassword);
    }
    
    public static boolean passwordCheck(final String inputPassword,final String  encryptedPassword){
        boolean flag=false;
        if (PASSWORD_ENCRYPTOR.checkPassword(inputPassword, encryptedPassword)) {
            flag=true;
          } 
        return flag;
    }
}
